<?php

//网站前台
class IndexController extends FrontBaseC {

    //网站首页
    public function actionIndex() {

        //侧边导航//所有的分类到二级，，，
        $arrSignMenu = CategoryModel::getListMenu(2);
        //print_r($arrSignMenu);exit;
        $this->assign('signMenu', $arrSignMenu);
        //banner图
        $arrAd = array(
            0 => AdvertisingModel::getListType(1),   //首页banner图
            1 => AdvertisingModel::getListType(2),            //banner底下图片
            2 => AdvertisingModel::getListType(3),            //banner测边图片
        );
        $this->assign('ad', $arrAd);

        //首页轮播商品(姑娘们在败什么)
        $arrData = GoodsModel::getVariedGoods('', '', '', '', 1, 'default', '', '', false, true);
        $this->assign('carousel', $arrData);



        //友情链接
/*        $arrLink = LinkModel::getList();
        $this->assign('link', $arrLink);*/



        //首页显示的产品数据
        $arrData = GoodsModel::getDataIndex();
        $this->assign('index_data', $arrData);

        $article[0] = ArticlesModel::getDataDetail(367);
        $article[1] = ArticlesModel::getDataDetail(368);
        $this->assign('article', $article);



        $this->render();
    }

    /**
     * 分类页
     * 需要分页,
     * 每页显示多少
     * @return [type] [description]
     */
    public function actionGoods(){

        $pagesize = 40;
        $page = Yii::app()->request->getParam('page');
        $mid = Yii::app()->request->getParam('mid');
        $cid = Yii::app()->request->getParam('cid');
        $tid = Yii::app()->request->getParam('tid');
        $order = Yii::app()->request->getParam('order');
        $page = empty($page) ? 1: $page;//第几页          
        $mid = empty($mid) ? '': $mid;//模块ID              
        $cid = empty($cid) ? '': $cid;//分类Id              
        $tid = empty($tid) ? '': $tid;//标签列表          
        $order = empty($order) ? 'default': $order;//标签列表   
        $arr = array(
            'pagesize' => $pagesize,
            'page' => $page,
            'mid' => $mid,
            'cid' => $cid,
            'tid' => $tid,
            'order' => $order,
        );
        $this->assign($arr);



        if(!$mid && !$cid){
            $this->error('请求出错');
        }

        switch ($order) {
            //销量从大到小
            case 1:
                $order = 'Sales DESC,GoodsID DESC';
                break;
            //价格从小到大
            case 2:
                $order = 'PromoPrice asc,GoodsID DESC';
                break;
            //价格从大到小
            case 3:
                $order = 'PromoPrice DESC,GoodsID DESC';
                break;
            //按人气排名
            case 4:
                $order = 'View DESC,GoodsID DESC';
                break;
            case 5:
                $order = 'zonghe';//综合排序，后面实现
                break;                                            
            default:
                # code...
                break;
        }

        //展示的商品
        //模块，分类，专场，标签，是否首页轮播，排序，第几页，一页多少，是否打乱顺序，是否缓存，缓存时间
        $datas = GoodsModel::getVariedGoods($mid,$cid,'',$tid,'',$order,$page,40,true,true,600);
        $this->assign('data', $datas);
        //这个模块下面的标签
        //这个分类下面的标签
        //这个分类下面的 子分类
        if($mid){
            //找出这个模块的标签列表
            $strTag = ModuleModel::getOne($mid,'TagListIDs');
        }else if($cid){
            $strTag = CategoryModel::getDataDetail($cid,'TagListIDs');           
            $this->assign('cat', CategoryModel::getListCatID($cid,2));
        }else{
            $strTag = '';
        }
        $tag = !empty($strTag) ? explode(',', $strTag) : array();
        $this->assign('tag', $tag);

        $this->render();
    }

    //每日特价
    public function actionOnsale(){
        $this->layout = 'theme.views.layouts.frontNoContent';
        $pagesize = 40;
        $page = Yii::app()->request->getParam('page');
        $cid = Yii::app()->request->getParam('cid');
        $page = empty($page) ? 1: $page;//第几页          
        $cid = empty($cid) ? '': $cid;//分类Id   
        $this->assign('cid',$cid);  
        if(IS_AJAX){
            $datas = GoodsModel::getVariedGoods('',$cid,'','','','onsale',$page,$pagesize,false,true,600);
            $content = $this->renderPartial('data', array('data' => $datas), true);
            $this->ajaxReturn(array('status' => 1, 'content' => $content));
        }        
        //$this->assign('data', $datas);      
        $this->render();
    }
    /**
     * 明日预告
     * @return [type] [description]
     */
    public function actionTomorrow(){
        $this->layout = 'theme.views.layouts.frontNoContent';
        $pagesize = 40;
        $page = Yii::app()->request->getParam('page'); 
        if(IS_AJAX){
            //第几页，每页显示多少条数据       
            $datas = GoodsModel::getTomorrow($page,$pagesize);            
            $content = $this->renderPartial('data', array('data' => $datas), true);
            $this->ajaxReturn(array('status' => 1, 'content' => $content));
        }       
        //$this->assign('data', $datas);  
        $this->render('onsale');        
    }




    /**
     * 限时特卖
     * @return [type] [description]
     */
    public function actionXianshi(){
        $this->layout = 'theme.views.layouts.frontNoContent';
        $this->render();
    }

    //正常
    public function actionCeshi1(){
        set_time_limit(0);
        $d = array();
        for($i=1;$i<100;$i++){
           $d[] = $i; 
        }
        $ddd = '';
        foreach ($d as $key => $val) {
            switch ($val) {
                case 1:
                    $ddd = 5;
                    break;
                case 2:
                    $ddd = 6;
                    break;
                case 3:
                    $ddd = 10;
                    break;
                case 4:
                    $ddd = 9;
                    break;
                case 5:
                    $ddd = 7;
                    break;
                case 6:
                    $ddd = 11;
                    break;
                case 7:
                    $ddd = 8;
                    break;
                case 8:
                    $ddd = 1;
                    break;
                case 9:
                    $ddd = 2;
                    break;
                case 10:
                    $ddd = 13;
                    break;
                case 11:
                    $ddd = 14;
                    break;
                case 12:
                    $ddd = 4;
                    break;
                case 13:
                    $ddd = 3;
                    break;
                case 14:
                    $ddd = 12;
                    break;
                case 22:
                    $ddd = 15;
                    break;
                case 23:
                    $ddd = 16;
                    break;
                case 24:
                    $ddd = 18;
                    break;
                case 25:
                    $ddd = 20;
                    break;
                case 29:
                    $ddd = 22;
                    break;
                case 30:
                    $ddd = 25;
                    break;
                case 31:
                    $ddd = 23;
                    break;
                case 32:
                    $ddd = 25;
                    break;
                case 33:
                    $ddd = 25;
                    break;
                case 34:
                    $ddd = 26;
                    break;
                case 41:
                    $ddd = 29;
                    break;
                case 43:
                    $ddd = 32;
                    break;
                case 42:
                    $ddd = 31;
                    break;
                case 39:
                    $ddd = 30;
                    break;
                case 40:
                    $ddd = 34;
                    break;
                case 44:
                    $ddd = 31;
                    break;
                
                default:
                    # code...
                    break;
            }
            if($ddd){
                $sql = "update tk_goods set CatID = {$ddd} where CatID = {$val}";
                echo $sql;
                echo "</br>"; 
                unset($ddd);               
            }

        }
    }



    public function actionError(){

    }
}
